<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>表情包</title>
    <style>
        .list {
            display: flex;
            text-align: center;
        }
    </style>
</head>

<body>
    <div class="list"></div>
    <button class="prev">上一页</button>
    <button class="next">下一页</button>
</body>

</html>
<script src="../js/表情包 promise-ajax.js"></script>
<script>
    let oPrev = document.querySelector('.prev');
    oPrev.onclick = function () {
        if (page > 1) {
            ajax('get', `https://yantianfeng.com/api/emotion`, { page: --page, count: 10 }).then((data) => {
                console.log(data);
                var str = data.emotions.map((item, index) => {
                    return `<div><img src="${item.url}"/><div>${item.title}</div></div>`
                }).join('')

                document.querySelector('.list').innerHTML = str
            })
        } else {
            document.querySelector('.prev').disabled = true;
        }
    }

    //下一页的页面，渲染表情
    document.querySelector('.next').onclick=function(){
        if(page<4){
            ajax('get',`https://yantianfeng.com/api/emotion`,{page:++page,count:10}).then((data)=>{
                console.log(data);
                var str=data.emotions.map((item,index)=>{
                    return `<div><img src="${item.url}"/><div>${item.title}</div></div>`
                }).join('')
                document.querySelector('.list').innerHTML=str
            });

        }else{

            document.querySelector('.next').disabled=true;
        }
    }
</script>